# coding:utf8
import pymysql.cursors

#python链接mysql数据源
class Jdbc():

    def addCompany(self,company):
        # 获取数据库链接
        conn = pymysql.connect(
            host='47.100.169.103',
            user='root',
            passwd='guoda',
            db='reptilian',
        )
        #获取cursor对象1
        cursor = conn.cursor()
        #执行sql语句
        sql = "INSERT INTO company VALUES (null,'"+company[0]+"','"+company[1]+"','"+company[2]+"','"+company[3]+"','"+company[4]+"','"+company[5]+"','"+company[6]+"','"+company[7]+"','"+company[8]+"','"+company[9]+"','"+company[10]+"','"+company[11]+"','"+company[12]+"','"+company[13]+"')"
        print(sql)
        try:
            cursor.execute(sql)
        except Exception as e:
            print(e)
            # 回滚事务
            conn.rollback()
        #提交事务
        conn.commit()
        #关闭游标
        conn.cursor().close()
        #关闭connection
        conn.close()


